//
//  WidthDrawRecordCell.swift
//  E-CycleForShop
//
//  Created by enghou on 17/3/9.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

import UIKit

class WidthDrawRecordCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    var model : MineMessageModel? {
        didSet{
            statusLbl.text = model?.status
            let size1 = statusLbl.text!.StringSize(font: statusLbl.font)
            statusLbl.frame = CGRect.init(origin: CGPoint.init(x: 32 * YXWidthScale, y: 28 * YXHeightScale), size: size1)//good
            let size2 = model!.amount.StringSize(font: UIFont.boldSystemFont(ofSize: 56 * YXWidthScale))
            let totalWidth = YXDeviceWidth - 60 * YXWidthScale
            imgView.frame = CGRect.init(origin: CGPoint.init(x: totalWidth / 2 - size2.width / 2 - 38 * YXWidthScale, y: 104 * YXHeightScale), size: CGSize.init(width: 58 * YXWidthScale, height: 58 * YXHeightScale))
            if model!.type == "支付宝" {
                imgView.image = UIImage.load(name: "icon_choice_pay")
            }else if model!.type == "微信" {
                imgView.image = UIImage.load(name: "icon_choice_wechat")
            }
            amountLbl.text = model!.amount
            amountLbl.frame = CGRect.init(origin: CGPoint.init(x: imgView.right() + 18 * YXWidthScale, y: imgView.bottom() - imgView.height() / 2 - size2.height / 2), size: size2)
            let siz = "元".StringSize(font: yuan.font)
            yuan.frame = CGRect.init(x: amountLbl.right(), y: amountLbl.bottom() - amountLbl.height()  + siz.height / 2, width: siz.width, height: siz.height)
            //如果不到7个以上则显示全部,否则加密中间四个
            var str = ""
            if model!.account.characters.count > 7 {
                let idx = model!.account.index(model!.account.startIndex, offsetBy: 3)
                let encryptAccount = model!.account.replacingCharacters(in: idx..<model!.account.index(idx, offsetBy: 4), with: "****")
                str = model!.type + "账户: " + encryptAccount
            } else {
                str = model!.type + "账户: " + model!.account
            }
            let accountStr = NSMutableAttributedString.init(string: str)
            accountStr.addAttributes([NSAttributedStringKey.font : UIFont.systemFont(ofSize: 28 * YXWidthScale),NSAttributedStringKey.foregroundColor : UIColor.colorWithHexString(hex: "2c2c2c")], range: NSRange.init(location: 0, length: accountStr.length))
            accountStr.addAttributes([NSAttributedStringKey.foregroundColor : UIColor.colorWithHexString(hex: "646464")], range: NSRange.init(location: 6, length: accountStr.length - 6))
            let size3 = accountStr.size()
            accountLbl.frame = CGRect.init(origin: CGPoint.init(x: 32 * YXWidthScale, y: 228 * YXHeightScale), size: size3)
            accountLbl.attributedText = accountStr
            
            //最后设置提现时间
            let dateStr = "提现时间: " + model!.timeStr
            let timeStr = NSMutableAttributedString.init(string: dateStr)
            timeStr.addAttributes([NSAttributedStringKey.font : UIFont.systemFont(ofSize: 28 * YXWidthScale),NSAttributedStringKey.foregroundColor : UIColor.colorWithHexString(hex: "2c2c2c")], range: NSRange.init(location: 0, length: timeStr.length))
            let size4 = dateStr.StringSize(font: UIFont.systemFont(ofSize: 28 * YXWidthScale))
            timeStr.addAttributes([NSAttributedStringKey.foregroundColor : UIColor.colorWithHexString(hex: "646464")], range: NSRange.init(location: 5, length: timeStr.length - 5))
            dateLbl.attributedText = timeStr
            dateLbl.frame = CGRect.init(origin: CGPoint.init(x: accountLbl.left(), y: accountLbl.bottom() + 32 * YXHeightScale), size: size4)
        }
    }
    
    private var statusLbl = UILabel.init()
    private var imgView = UIImageView.init()
    private var amountLbl = UILabel.init()
    private var accountLbl = UILabel.init()
    private var dateLbl = UILabel.init()
    private var yuan = UILabel.init()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = UIColor.colorWithHexString(hex: "f3f3f5")
//        self.contentView.backgroundColor = UIColor.black
        let container = UIView.init()
        container.frame = CGRect.init(x: 30 * YXWidthScale, y: 20 * YXHeightScale, width: YXDeviceWidth - 60 * YXWidthScale, height: 360 * YXHeightScale)
        container.backgroundColor = UIColor.white
        container.layer.cornerRadius = YXButtonCorner
        container.layer.borderColor = UIColor.colorWithHexString(hex: "dfdfdf").cgColor
        container.layer.borderWidth = YXHeightScale
        self.contentView.addSubview(container)
        statusLbl.textColor = UIColor.black
        statusLbl.font = UIFont.systemFont(ofSize: 32 * YXWidthScale)
        container.addSubview(statusLbl)
        
        container.addSubview(imgView)
        yuan.textColor = UIColor.black
        yuan.text = "元"
        yuan.font = UIFont.systemFont(ofSize: 32 * YXWidthScale)
        yuan.textAlignment = .center
        container.addSubview(yuan)
        amountLbl.textColor = UIColor.black
        amountLbl.font = UIFont.boldSystemFont(ofSize: 56 * YXWidthScale)
        container.addSubview(amountLbl)
        
        let line = UIView.init()
        line.frame = CGRect.init(origin: CGPoint.init(x: 32 * YXWidthScale, y: 192 * YXHeightScale), size: CGSize.init(width: YXDeviceWidth - 124 * YXWidthScale, height: YXHeightScale))
        line.backgroundColor = UIColor.colorWithHexString(hex: "ececec")
        container.addSubview(line)
        container.addSubview(accountLbl)
        container.addSubview(dateLbl)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
